function usecooldownsg1zstar()
  if useCDS == true then
    useCDS = false
    print("cooldowns are off")
  else
    useCDS = true
    print("cooldowns are on")
  end
end

function stung1zstar()
  if isStun == true then
    isStun = false
    print("turning off stun.")
  else
    isStun = true
    print("turning on stun.")
  end
end

-- function AoEToggle()
--   if not AoEFrame then
--     AoEFrame = CreateFrame("Frame", "AoEFrame", UIParent)
--     AoEFrame:SetFrameStrata("DIALOG")
--     AoEFrame:SetWidth("64")
--     AoEFrame:SetHeight("64")
--     isAoE_One = AoEFrame:CreateTexture("isAoE_One")
--     isAoE_One:SetTexture("Interface\\Addons\\_ccR\\sys\\1.tga")
--     isAoE_One:SetTexCoord(0,1,0,1)
--     isAoE_One:SetAllPoints(AoEFrame)
--     isAoE_Two = AoEFrame:CreateTexture("isAoE_Two")
--     isAoE_Two:SetTexture("Interface\\Addons\\_ccR\\sys\\2.tga")
--     isAoE_Two:SetTexCoord(0,1,0,1)
--     isAoE_Two:SetAllPoints(AoEFrame)
--     isAoE_Three = AoEFrame:CreateTexture("isAoE_Three")
--     isAoE_Three:SetTexture("Interface\\Addons\\_ccR\\sys\\3.tga")
--     isAoE_Three:SetTexCoord(0,1,0,1)
--     isAoE_Three:SetAllPoints(AoEFrame)
--     AoEFrame:SetPoint("CENTER")
--     AoEFrame:SetMovable()
--     AoEFrame:EnableMouse(true)
--     AoEFrame:RegisterForDrag("LeftButton")
--     AoEFrame:SetScript("OnDragStart", AoEFrame.StartMoving)
--     AoEFrame:SetScript("OnDragStop", AoEFrame.StopMovingOrSizing)
--     AoEFrame:SetUserPlaced(1)
--     -- isAoE_One:SetUserPlaced(1)
--     -- isAoE_Two:SetUserPlaced(1)
--     -- isAoE_Three:SetUserPlaced(1)
--   end
--   if isAoE == nil then
--     isAoE = 0
--     isAoE_One:Show()
--     isAoE_Two:Hide()
--     isAoE_Three:Hide()
--     return
--   end
--   if isAoE == 0 then
--     isAoE = 1
--     isAoE_One:Hide()
--     isAoE_Two:Show()
--     print("cleave on")
--   elseif isAoE == 1 then
--     isAoE = 2
--     isAoE_Two:Hide()
--     isAoE_Three:Show()
--     print("AoE on")
--   elseif isAoE == 2 then
--     isAoE = 0
--     isAoE_Three:Hide()
--     isAoE_One:Show()
--     print("single target on")
--   end
-- end

function pullallunitsm(spell)
  if not spell then return end
  if _pullMThrottle == nil then _pullMThrottle = 0 end
  if _pullMThrottle + .5 > GetTime() then return end
  _pullMThrottle = GetTime()
  spelltable = string.gsub(spell, "%s", "")
  _G["tNoObject"..spelltable] = {}
  _G["t"..spelltable] = {}
  for i = 1, GetTotalObjects(TYPE_UNIT) do
    ObjectCurrentM, name = nil
    ObjectCurrentM = GetObjectListEntry(i)
    if not ObjectCurrentM:GetAura("Misery, Sorrow, and Gloom") and not ObjectCurrentM:GetAura("Mark of Anguish") and not ObjectCurrentM:GetAura("Dark Meditation") then
      name = ObjectCurrentM:GetAura(spell, "", "PLAYER")
      if name == spell then table.insert(_G["t"..spelltable], ObjectCurrentM) end
      if name ~= spell and ObjectCurrentM:GetDistance() <= 40 and Player:CanAttack(ObjectCurrentM) and ObjectCurrentM:GetCreatureInfo() ~= "Critter" and ObjectCurrentM:GetCreatureInfo() ~= "Wild Pet" and ObjectCurrentM:InLineOfSight() and not ObjectCurrentM:IsDead() then table.insert(_G["tNoObject"..spelltable], --[[i,--]] ObjectCurrentM) end
    end
  end
end

function TargetList()
  if GetTotalObjects(TYPE_UNIT) ~= #TargetsPreliminary or GetTime() - tLastTargetList > 5 then
    TargetsPreliminary = {}
    for i = 1, GetTotalObjects(TYPE_UNIT) do
      _target = nil
      _target = GetObjectListEntry(i)
      table.insert(TargetsPreliminary)
    end
    tLastTargetList = GetTime()
  else
    for i = 1, #TargetsPreliminary do
      if TargetsPreliminary[i]:GetHealth() > 0 and Player:CanAttack(TargetsPreliminary[i]) and TargetsPreliminary[i]:GetCreatureInfo() ~= "Critter" and TargetsPreliminary[i]:GetCreatureInfo() ~= "Wild Pet" then
        table.insert(Targets)
      end
    end
    for i = 1, #Targets do
      if Targets[i]:GetHealth() == 0 then
        _G["remove"..i] = yes
      end
    end
    for i = #Targets, 1 do
      if _G["remove"..i] then
        table.remove(Targets, i)
        _G["remove"..i] = false
      end
    end
  end
end

function HealerList()
end

function round(num, idp)
   local mult = 10^(idp or 0)
   return math.floor(num * mult + 0.5) / mult
end

function GroupComposer()
    if not GroupComposerFrameCheck then GroupComposerFrame() end
    local groupplayernumber = GetNumGroupMembers()
    local roletable = {tanks = {}, healers = {}, dps = {}, none = {}}
    
    if GetRaidDifficultyID() == 3 or GetRaidDifficultyID() == 5 then
      for i = 1, groupplayernumber do

        local name = GetRaidRosterInfo(i)

        if UnitGroupRolesAssigned("raid"..i) == "TANK" then
          table.insert(roletable.tanks, {name, "raid"..i})
        elseif UnitGroupRolesAssigned("raid"..i) == "HEALER" then
          table.insert(roletable.healers, {name, "raid"..i})
        elseif UnitGroupRolesAssigned("raid"..i) == "DAMAGER" then
          table.insert(roletable.dps, {name, "raid"..i})
        elseif UnitGroupRolesAssigned("raid"..i) == "NONE" then
          InitiateRolePoll()
          table.insert(roletable.none, {name, "raid"..i})
        end
      end

      local confirmedroles = #roletable.tanks + #roletable.healers + #roletable.dps

      if confirmedroles == 10 then return
      elseif confirmedroles + #roletable.none == 10 then InitiateRolePoll() return
      elseif confirmedroles + #roletable.none < 10 then
        
        local missingpeople = 10 - confirmedroles
        local missingtanks, missinghealers, missingdps

        if #roletable.tanks ~= 2 then
          missingtanks = ""..2-#roletable.tanks.." tank(s) "
        else missingtanks = "" end
        
        if #roletable.healers ~= 2 then
          missinghealers = ""..2-#roletable.healers.." healers(s) "
        else missinghealers = "" end

        if #roletable.dps ~= 6 then
          missingdps = ""..6-#roletable.dps.." dps "
        else missingdps = "" end

        GroupComposerFrame("LF"..missingpeople.."M "..missingtanks..missinghealers..missingdps.."550+ 10NM SoO at .")
      end
    end
    
    if GetRaidDifficultyID() == 4 or GetRaidDifficultyID() == 6 then
      for i = 1, groupplayernumber do

        local name = GetRaidRosterInfo(groupplayernumber)

        if UnitGroupRolesAssigned("raid"..i) == "TANK" then
          table.insert(roletable.tanks, {name, "raid"..i})
        elseif UnitGroupRolesAssigned("raid"..i) == "HEALER" then
          table.insert(roletable.healers, {name, "raid"..i})
        elseif UnitGroupRolesAssigned("raid"..i) == "DAMAGER" then
          table.insert(roletable.dps, {name, "raid"..i})
        elseif UnitGroupRolesAssigned("raid"..i) == "NONE" then
          InitiateRolePoll()
          table.insert(roletable.none, {name, "raid"..i})
        end
      end

      local confirmedroles = #roletable.tanks + #roletable.healers + #roletable.dps

      if confirmedroles == 25 then return
      elseif confirmedroles + #roletable.none == 25 then InitiateRolePoll() return
      elseif confirmedroles + #roletable.none < 25 then

        local missingpeople = 25 - confirmedroles
        local missingtanks, missinghealers, missingdps
        
        if #roletable.tanks ~= 2 then
          missingtanks = ""..2-#roletable.tanks.." tank(s) "
        else missingtanks = "" end

        if #roletable.healers ~= 5 then
          missinghealers = ""..5-#roletable.healers.." healers(s) "
        else missinghealers = "" end

        if #roletable.dps ~= 18 then
          missingdps = ""..18-#roletable.dps.." dps "
        else missingdps = "" end

        GroupComposerFrame("LF"..missingpeople.."M "..missingtanks..missinghealers..missingdps.."550+ 25NM SoO at .")
      end
    end
end

function GroupComposerFrame(turn)
  if turn then
    groupcomposereditbox:SetFocus()
    groupcomposereditbox:SetText(turn)
    groupcomposereditbox:HighlightText()
    groupcomposereditbox:Show()
    button:Show()
    return
  end
  GroupComposerFrameCheck = true
  groupcomposereditbox = CreateFrame("EditBox", nil, UIParent)
  groupcomposereditboxLeft = groupcomposereditbox:CreateTexture(nil, "BACKGROUND")
  groupcomposereditboxRight = groupcomposereditbox:CreateTexture(nil, "BACKGROUND")
  groupcomposereditboxMiddle = groupcomposereditbox:CreateTexture(nil, "BACKGROUND")
  do
    groupcomposereditboxLeft:SetTexture("Interface\\ChatFrame\\UI-ChatInputBorder-Left")
    groupcomposereditboxLeft:SetHeight(32)
    groupcomposereditboxLeft:SetWidth(32)
    groupcomposereditboxLeft:SetPoint("LEFT", -14, 0)
    groupcomposereditboxLeft:SetTexCoord(0, 0.125, 0, 1)
    groupcomposereditboxRight:SetTexture("Interface\\ChatFrame\\UI-ChatInputBorder-Right")
    groupcomposereditboxRight:SetHeight(32)
    groupcomposereditboxRight:SetWidth(32)
    groupcomposereditboxRight:SetPoint("RIGHT", 6, 0)
    groupcomposereditboxRight:SetTexCoord(0.875, 1, 0, 1)
    groupcomposereditboxMiddle:SetTexture("Interface\\ChatFrame\\UI-ChatInputBorder-Right")
    groupcomposereditboxMiddle:SetHeight(32)
    groupcomposereditboxMiddle:SetWidth(1)
    groupcomposereditboxMiddle:SetPoint("LEFT", groupcomposereditboxLeft, "RIGHT")
    groupcomposereditboxMiddle:SetPoint("RIGHT", groupcomposereditboxRight, "LEFT")
    groupcomposereditboxMiddle:SetTexCoord(0, 0.9375, 0, 1)
  end
  groupcomposereditbox:SetHeight(32)
  groupcomposereditbox:SetWidth(250)
  groupcomposereditbox:SetPoint("TOP", 0, -16)
  groupcomposereditbox:SetFontObject("GameFontHighlight")
  groupcomposereditbox:SetTextInsets(0, 0, 0, 1)
  groupcomposereditbox:SetFocus()
  --   groupcomposereditbox:SetText("http://www.deadlybossmods.com")
  groupcomposereditbox:HighlightText()
  button = CreateFrame("Button", nil, groupcomposereditbox)
  button:SetHeight(24)
  button:SetWidth(75)
  button:SetPoint("BOTTOM", 0, -20)
  button:SetNormalFontObject("GameFontNormal")
  button:SetHighlightFontObject("GameFontHighlight")
  button:SetNormalTexture(button:CreateTexture(nil, nil, "UIPanelButtonUpTexture"))
  button:SetPushedTexture(button:CreateTexture(nil, nil, "UIPanelButtonDownTexture"))
  button:SetHighlightTexture(button:CreateTexture(nil, nil, "UIPanelButtonHighlightTexture"))
  button:SetText(OKAY)
  button:SetScript("OnClick", function(self)
         groupcomposereditbox:Hide()
         button:Hide()
  end)
end

function _ThrottleFrame()
  if ccrPlayerName() == "Lhae" then
    if not tRuneOfPower then
      tRuneOfPower = 0
      _RuneToggle = 0
    end
  end
  if not ThrottleFrame then
    ThrottleFrame = CreateFrame("Frame", "ThrottleFrame", UIParent)
    ThrottleFrame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
    ThrottleFrame:SetScript("OnEvent", ThrottleFrameFunction)
  end
end

function ThrottleFrameFunction(self, registeredevent, ...)
  local timestamp, event, hidecaster, sourceguid, sourcename, sourceflags, sourceraidflags, destguid, destname, destflags, destraidflags = ...

  if event == "SPELL_CAST_SUCCESS" and sourcename == "Plantronic" and isStun then
    local spellid= select(12, ...)
    if ccrPlayerHasTalent("Fist of Justice") then
      if spellid == 105593 then
        isStun = false
        print("Stun Turned Off.")
        return
      end
    else
      if spellid == 853 then
        isStun = false
        print("Stun Turned Off.")
        return
      end
    end
  end

  if event == "SPELL_CAST_SUCCESS" and sourcename == "Mÿway" then
    local spellid = select(12, ...)
    if spellid == 781 then
      HD2()
      -- FaceDirection(degrees)
      -- ToggleAutoRun()
      -- RemoveEventCallback(HD1)
      return
    end
  end

  if event == "SPELL_CAST_START" and sourcename == "Thok the Bloodthirsty" then
    local _, _, _, _, _, tEnd = UnitCastingInfo("boss1")
    ThokThrottle = tEnd
  end

  if event == "SPELL_AURA_APPLIED" and sourcename == "Lhae" then
    local spellid = select(12, ...)
    if spellid == 146046 then _PBI = GetTime() return end
  end
  if event == "SPELL_CAST_SUCCESS" and sourcename == "Lhae" then
    local spellid = select(12, ...)
    if spellid == 116011 then
      _RuneToggle = GetTime()+0.5
      tRuneOfPower = GetTime()
      return
    end
  end

  if event == "SPELL_CAST_START" and sourcename == "Athm" then
    local spellid = select(12, ...)
    if spellid == 348 then _ImmolateThrottle = 1 return end
  end
  if event == "SPELL_CAST_SUCCESS" and sourcename == "Athm" then
    local spellid = select(12, ...)
    if spellid == 348 then
      _ImmolateThrottle = 0
      _G[destguid.." ImmolateThrottle"] = 2
      _G[destguid.." ImmolateOldCrit"] = GetSpellCritChance(3)
      return
    end
    return
  end
  if (event == "SPELL_AURA_APPLIED" or event == "SPELL_AURA_REFRESH") and sourcename == "Athm" then
    local spellid = select(12, ...)
    if spellid == 348 then
      _G[destguid.." ImmolateThrottle"] = 0
      return
    end
    return
  end
  if event == "SPELL_CAST_FAILED" and sourcename == "Athm" then
    local spellid = select(12, ...)
    if spellid == 348 then
      _ImmolateThrottle = 0
      return
    end
  end
end

function InterruptTrainer()
  local interruptid
  local unitclass = {UnitClass("player")}
  if interruptid == nil then
    if unitclass[2] == "WARRIOR" then
      if ccrPlayerHasTalent("Disrupting Shout") then interruptid = {102060, 6552}
      else
        interruptid = {6552}
      end
    elseif unitclass[2] == "PALADIN" then 
      interruptid = 96231
    elseif unitclass[2] == "HUNTER" then
      if GetSpecialization() == 2 then interruptid = 34490
      else
        interruptid = 147362
      end
    elseif unitclass[2] == "DRUID" then
      if GetSpecialization() == 1 then interruptid = 78675
      elseif GetSpecialization() == 2 then interruptid = 106839
      elseif GetSpecialization() == 3 then interruptid = 106839
      elseif GetSpecialization() == 4 then return
      end
    elseif unitclass[2] == "MONK" then interruptid = 116075
    elseif unitclass[2] == "DEATHKNIGHT" then interruptid = {47528, 47476}
    elseif unitclass[2] == "MAGE" then interruptid = 2139
    elseif unitclass[2] == "PRIEST" then
      if GetSpecialization() == 3 then interruptid = 15487
      else
        return
      end
    elseif unitclass[2] == "ROGUE" then interruptid = 1766
    elseif unitclass[2] == "SHAMAN" then interruptid = 57994
    elseif unitclass[2] == "WARLOCK" then
      if ccrPlayerHasTalent("Grimoire of Supremacy") then interruptid = 115781
      else
        interruptid = 19647
      end
    end
  end
  if UnitCastingInfo("target") == "Mind Spike" or UnitCastingInfo("target") == "Mocking Blast" or UnitCastingInfo("target") == "Empowered Chain Heal" or UnitCastingInfo("target") == "Corruption Shock" or UnitCastingInfo("target") == "Hurl Corruption" or UnitCastingInfo("target") == "Chain Heal" or UnitCastingInfo("target") == "Arcane Shock" or UnitCastingInfo("target") == "Magistrike" then
    ccrCast(interruptid)
  end
end

function TauntTrainer()
  local unitclass = {UnitClass("player")}
  if tauntid == nil then
    if unitclass[2] == "WARRIOR" then
      tauntid = 355
    elseif unitclass[2] == "PALADIN" then
      tauntid = 62124
    elseif unitclass[2] == "DRUID" then
      tauntid = 6795
    elseif unitclass[2] == "MONK" then
      tauntid = 115546
    elseif unitclass[2] == "DEATHKNIGHT" then
      tauntid = {56222, 49576}
    end
  end
  -- if not Focus then return end
  -- if not Target then return end
  local othertank = UnitName("focus")
  -- if UnitThreatSituation("player", "target") then return end
  if Focus and Target and UnitThreatSituation("player", "target") ~= nil then
    if UnitThreatSituation("player", "target") < 2 and UnitName("target") == "Immerseus" and UnitAura(othertank, "Corrosive Blast") and not UnitAura("player", "Corrosive Blast") then
      ccrCast(tauntid)
    elseif UnitThreatSituation("player", "target") < 2 and UnitName("target") == "Sha of Pride" and UnitAura(othertank, "Wounded Pride") and not UnitAura("player", "Wounded Pride") then
      ccrCast(tauntid)
    elseif UnitThreatSituation("player", "target") < 2 and UnitName("target") == "Galakras" and select(4, UnitAura(othertank, "Flames of Galakrond")) > 2 and not UnitAura("player", "Flames of Galakrond") then
      ccrCast(tauntid)
    elseif UnitThreatSituation("player", "target") < 2 and UnitName("target") == "Iron Juggernaut" and select(4, UnitAura(othertank, "Ignite Armor")) > 2 and not UnitAura("player", "Ignite Armor") then
      ccrCast(tauntid)
    -- elseif UnitThreatSituation("player", "target") < 2 and UnitName("target") == "Earthbreaker Haromm" and select(4, UnitAura(othertank, "Froststorm Strike")) > 4 and not UnitAura("player", "Froststorm Strike") then
    --   ccrCast(tauntid)
    elseif UnitThreatSituation("player", "target") < 2 and UnitName("target") == "General Nazgrim" and select(4, UnitAura(othertank, "Sundering Blow")) > 2 and not UnitAura("player", "Sundering Blow") then
      ccrCast(tauntid)
    -- elseif UnitThreatSituation("player", "target") < 2 and UnitName("target") == "Malkorok" and select(4, UnitAura(othertank, "Fatal Strike")) > 14 and not UnitAura("player", "Fatal Strike") then
    -- ccrCast(tauntid)
    elseif UnitThreatSituation("player", "target") < 2 and UnitName("target") == "Thok the Bloodthirsty" and select(4, UnitAura(othertank, "Panic")) > 2 and not UnitAura("player", "Panic") then
      ccrCast(tauntid)
    elseif UnitThreatSituation("player", "target") < 2 and UnitName("target") == "Thok the Bloodthirsty" and select(4, UnitAura(othertank, "Acid Breath")) > 2 and not UnitAura("player", "Acid Breath") then
      ccrCast(tauntid)
    elseif UnitThreatSituation("player", "target") < 2 and UnitName("target") == "Thok the Bloodthirsty" and select(4, UnitAura(othertank, "Scorching Breath")) > 2 and not UnitAura("player", "Scorching Breath") then
      ccrCast(tauntid)
    elseif UnitThreatSituation("player", "target") < 2 and UnitName("target") == "Siegecrafter Blackfuse" and select(4, UnitAura(othertank, "Electrostatic Charge")) > 2 and not UnitAura("player", "Electrostatic Charge") then
      ccrCast(tauntid)
    elseif UnitThreatSituation("player", "target") < 2 and UnitName("target") == "Garrosh Hellscream" and select(4, UnitAura(othertank, "Gripping Despair")) > 2 and not UnitAura("player", "Gripping Despair") then
      ccrCast(tauntid)
    elseif UnitThreatSituation("player", "target") < 2 and UnitName("target") == "Garrosh Hellscream" and select(4, UnitAura(othertank, "Empowered Gripping Despair")) > 2 and not UnitAura("player", "Empowered Gripping Despair") then
      ccrCast(tauntid)
    end
  end
end

function TierBonusChecker()
  if not tierslots then tierslots = {1, 3, 5, 7, 10} end
  if not tierid then
    tierid = {}
    tierid.head = {99084, 99576, 99161, 99398}
    tierid.shoulder = {99079, 99659, 99153, 99401}
    tierid.chest = {99078, 99658, 99152, 99400}
    tierid.legs = {99077, 99657, 99162, 99399}
    tierid.hands = {99083, 99575, 99160, 99397}
  end
  SetNumber = 0
  local headid = GetInventoryItemID("player", 1)
  local shoulderid = GetInventoryItemID("player", 3)
  local chestid = GetInventoryItemID("player", 5)
  local legsid = GetInventoryItemID("player", 7)
  local handsid = GetInventoryItemID("player", 10)
  for i, v in pairs(tierid.head) do
    if headid == v then SetNumber = SetNumber+1 break end
  end
  for i, v in pairs(tierid.shoulder) do
    if shoudlerid == v then SetNumber = SetNumber+1 break end
  end
  for i, v in pairs(tierid.chest) do
    if chestid == v then SetNumber = SetNumber+1 break end
  end
  for i, v in pairs(tierid.legs) do
    if legsid == v then SetNumber = SetNumber+1 break end
  end
  for i, v in pairs(tierid.hands) do
    if handsid == v then SetNumber = SetNumber+1 break end
  end
  return SetNumber
end

function HunterDisengage()

 _ThrottleFrame()
 
 degrees = select(4, Player:GetLocation())
 
 if degrees+math.pi > 1.99999831016228*math.pi then
    degreestwo = degrees-math.pi
    degreestwor = round(degreestwo, 6)
    FaceDirection(degreestwo)
 else
    degreestwo = degrees+math.pi
    degreestwor = round(degreestwo, 6)     
    FaceDirection(degreestwo)
 end
 
 SetTimerCallback(HD1, 10)
end

function HD1()
   if round(select(4, Player:GetLocation()), 6) == degreestwor then
      CastSpellByID(781)
   end
end

function HD2()
  RemoveEventCallback(HD1)
  FaceDirection(degrees)
  -- ToggleAutoRun()
end

function TicksRemaining(spell)
  local spell = spell
  if spell == 980 then
    spell = "Agony"
  elseif spell == 172 then
    spell = "Corruption"
  elseif spell == 48181 then
    spell = "Haunt"
  elseif spell == 27243 then
    spell = "Seed of Corruption"
  elseif spell == 30108 then
    spell = "Unstable Affliction"
  elseif spell == 103103 then
    spell = "Malefic Grasp"
  elseif spell == 1120 then
    spell = "Drain Soul"
  elseif spell == 348 then
    spell = "Immolate"
  end
  local name, _, _, _, _, duration, expires = UnitDebuff("target", ""..spell.."", "", "PLAYER")
  if name then
    afflictiondots:ClearLines()
    afflictiondots:SetUnitDebuff("target", IndexFinder(spell), "PLAYER")
    local tickevery = string.match(afflictiondotsTextLeft2:GetText(), '%d+%.%d+')
    return ceil((expires-GetTime())/tickevery)
  else
    return 0
  end
end

function IndexFinder(spell)
  for i = 1, 40 do
    if UnitDebuff("target", i, "PLAYER") == spell then
      return i
    end
  end 
end

function PandemicNewTotalTicks(spell)
  if spell == 980 then local spell = "Agony"
  elseif spell == 172 then local spell = "Corruption"
  elseif spell == 48181 then local spell = "Haunt"
  elseif spell == 27243 then local spell = "Seed of Corruption"
  elseif spell == 30108 then local spell = "Unstable Affliction"
  elseif spell == 103103 then local spell = "Malefic Grasp"
  elseif spell == 1120 then local spell = "Drain Soul"    
  end
  local name, _, _, _, _, duration, expires = UnitDebuff("target", ""..spell.."", "", "PLAYER")
  if name then
    if expires-GetTime() >= tAfflictionBaseDuration.spell*1.5 then tNewDuration = tAfflictionBaseDuration.spell*1.5
    else tNewDuration = expires-GetTime()+tAfflictionBaseDuration.spell
    end
    return tNewDuration/(2/(1+UnitSpellHaste("player")/100))
  else
    return tAfflictionBaseDuration.spell/(2/(1+UnitSpellHaste("player")/100))
  end
end
